package day2.demo2.inter;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyIn implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object o) throws Exception {
        System.out.println("ip:"+req.getRemoteAddr()+"访问了"+o);
        System.out.println(req.getSession().getAttribute("username"));
        if(req.getSession().getAttribute("username")==null){
            System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            resp.sendRedirect("/html/demo2/login.html");
            return false;//true:放行，false：流程中断
        }
        return true;
    }
}